<?php

namespace yiike\credit\backend\controllers;

use yiike\credit\backend\controllers\base\CreditController as BaseCreditController;

use \yiike\credit\models\CreditRecord;

/**
 * This is the class for controller "CreditController".
 */
class CreditController extends BaseCreditController {

    public function actionEdit($user_id) {
        //$this->title = '预存';
        $model          = new CreditRecord();
        $model->user_id = $user_id;
        try {
            if ($model->load($_POST)) {
                \Yii::$app->credit->update($user_id, $model->value1, $model->value2, $model->value3, $model->memo);
                $this->redirect(\yii\helpers\Url::previous());
            } elseif (!\Yii::$app->request->isPost) {
                $model->load($_GET);
            }
        } catch (\yii\base\Exception $e) {
            $msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
            $model->addError('_exception', $msg);
        }
        return $this->render('edit', ['model' => $model]);
    }

}
